package adminejb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.validation.ValidationException;

import repositories.CityRepository;
import specifications.CitySpecification;
import validator.ValidationService;
import entities.City;

@Stateless
@LocalBean
public class CityBean implements CityBeanLocal {
	/**
     * Default constructor. 
     */
			
    public CityBean() {
    }
    
    public void createCity(City city) {
    	CityRepository cRep = new CityRepository();
    	cRep.Add(city);
    }
    
    public void updateCity(City city) {
    	CityRepository cRep = new CityRepository();
    	cRep.Update(city);
    }
    
    public void deleteCity(String citycode) {
    	CityRepository cRep = new CityRepository();
    	cRep.FindAll();
    	CitySpecification cs = new CitySpecification("cityCode", citycode);
    	ArrayList<City> list = cRep.findBySpecification(cs);
    	cRep.Delete(list.get(0));
    }
        
    public ArrayList<City> getAllCities() {
    	CityRepository cr = new CityRepository();
		cr.FindAll();
		return cr.CityList;
    }
    
    public City findCity(String attr, String value) {
    	
    	CityRepository cityRep = new CityRepository();
    	cityRep.FindAll();
    	CitySpecification cs = new CitySpecification(attr, value);
    	ArrayList<City> list = cityRep.findBySpecification(cs);
    	return list.get(0);
    	
    }
}
